package sz.szsmk.citizencard.mvp.presenter;

import android.util.Log;
import android.widget.Toast;

import com.google.gson.Gson;
import com.squareup.okhttp.Request;
import com.youzan.spiderman.utils.MD5Utils;
import com.zhy.http.okhttp.OkHttpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import java.util.List;

import javax.inject.Inject;

import rx.functions.Action1;
import sz.szsmk.citizencard.DaggerApplication;
import sz.szsmk.citizencard.log.L;
import sz.szsmk.citizencard.model.network.GsdxNetApi;
import sz.szsmk.citizencard.model.network.bean.request.AccessTokenRequest;
import sz.szsmk.citizencard.model.network.bean.request.GetOrderOpenid;
import sz.szsmk.citizencard.model.network.bean.request.HomeWeathReq;
import sz.szsmk.citizencard.model.network.bean.request.IBaseRequest;
import sz.szsmk.citizencard.model.network.bean.request.NoticeMainReq;
import sz.szsmk.citizencard.model.network.bean.request.QueryPageResourceReq;
import sz.szsmk.citizencard.model.network.bean.request.UserBehaviorBrowseReq;
import sz.szsmk.citizencard.model.network.bean.request.UserBehaviorReq;
import sz.szsmk.citizencard.model.network.bean.response.BaseBean;
import sz.szsmk.citizencard.model.network.bean.response.CloudFlashRes;
import sz.szsmk.citizencard.model.network.bean.response.FirstSearchUserLevelRes;
import sz.szsmk.citizencard.model.network.bean.response.GetOrderOpenidRes;
import sz.szsmk.citizencard.model.network.bean.response.GetResourceReq;
import sz.szsmk.citizencard.model.network.bean.response.HomeHeadFuncResponse;
import sz.szsmk.citizencard.model.network.bean.response.HomeWeathRes;
import sz.szsmk.citizencard.model.network.bean.response.IUserInfo;
import sz.szsmk.citizencard.model.network.bean.response.NoticeMainres;
import sz.szsmk.citizencard.model.network.bean.response.OneWordRes;
import sz.szsmk.citizencard.model.network.bean.response.QueryAllFunctionNewRes;
import sz.szsmk.citizencard.model.network.bean.response.QueryInterductionAreaRes;
import sz.szsmk.citizencard.model.network.bean.response.QueryMainPageFunctionRes;
import sz.szsmk.citizencard.model.network.bean.response.QueryPageResourceRes;
import sz.szsmk.citizencard.model.network.bean.response.SeleciUserAuthRes;
import sz.szsmk.citizencard.model.network.clarkbean.response.AreaInfoResponse;
import sz.szsmk.citizencard.mvp.contract.IAPPMainContact;
import sz.szsmk.citizencard.mvp.contract.IHomeContact;
import sz.szsmk.citizencard.mvp.contract.INewsContact;
import sz.szsmk.citizencard.retrofitrxjava.ErrorAction;
import sz.szsmk.citizencard.retrofitrxjava.NetworkDateSources;
import sz.szsmk.citizencard.retrofitrxjava.SubscribeResult;
import sz.szsmk.citizencard.ui.adapter.bean.AppHomeCardBean;
import sz.szsmk.citizencard.ui.fragment.MainFragment;
import sz.szsmk.citizencard.util.ACache;
import sz.szsmk.citizencard.util.AndroidUtils;
import sz.szsmk.citizencard.util.Constant;
import sz.szsmk.citizencard.util.IObjectSignatureUtil;
import sz.szsmk.citizencard.util.StringUtils;

/**
 * Copyright (c)2018
 * author: zdh
 * created on: 2018/12/18 15:32
 * description:
 */
public class APPHomePresenter extends IBasePresenter
        implements IAPPMainContact.IAPPMainPresenter<IAPPMainContact.IAPPMainView> {

    private NetworkDateSources mNetworkDateSource;
    GsdxNetApi gsdxNetApi;

    @Inject
    public APPHomePresenter(GsdxNetApi gsdxNetApi) {
        this.gsdxNetApi = gsdxNetApi;
        this.mNetworkDateSource = NetworkDateSources.getInstance();
    }


    @Override
    public void queryAllFunctionNew() {
        IBaseRequest baseRequest = new IBaseRequest();
        String json = new Gson().toJson(baseRequest);
        mNetworkDateSource.queryAllFunctionNew(baseRequest, new SubscribeResult<QueryAllFunctionNewRes>() {
            @Override
            protected void onOk(QueryAllFunctionNewRes response) {
                String json = new Gson().toJson(response);
                for (int i=0;i<=json.length()/2000;i++){
                    if(json.substring(2000*i).length()>2000){
                        L.e(Constant.TAG, "我的应用Log---" + json.substring(2000*i,2000*(i+1)));
                    }else {
                        L.e(Constant.TAG, "我的应用LogFinal---" + json.substring(2000*i));
                    }

                }
                L.e(Constant.TAG, "我的应用---" + json);
                ((IAPPMainContact.IAPPMainView) mView).queryAllFunctionNewSucc(response);
            }

            @Override
            protected void onFailure(QueryAllFunctionNewRes response) {
                super.onFailure(response);
                Toast.makeText(DaggerApplication.getIns(), response.getMessage(), Toast.LENGTH_SHORT).show();
            }

            @Override
            protected void onNext(QueryAllFunctionNewRes response) {
                super.onNext(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }

    @Override
    public void queryHeadFunc() {
        IBaseRequest baseRequest = IObjectSignatureUtil.getBaseRequest();
        String json = new Gson().toJson(baseRequest);
        L.e(Constant.TAG, json);
        mNetworkDateSource.queryHeadFunc(baseRequest, new SubscribeResult<HomeHeadFuncResponse>() {
            @Override
            protected void onOk(HomeHeadFuncResponse response) {
                if (response == null) {
                    return;
                }
                String json = new Gson().toJson(response);
               L.e(Constant.TAG, "queryHeadFunc响应:" + json);
                HomeHeadFuncResponse homeHeadFuncResponse = new Gson().fromJson(json, HomeHeadFuncResponse.class);
                Log.d("clark","11111111111111");
                ((IAPPMainContact.IAPPMainView) mView).queryHeadFuncSuccess(homeHeadFuncResponse);
                Log.d("clark","2222222222222222222");
            }

            @Override
            protected void onFailure(HomeHeadFuncResponse response) {
                super.onFailure(response);
                ((IAPPMainContact.IAPPMainView) mView).updataError(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }

    @Override
    public void queryAreaInfo() {
        IBaseRequest baseRequest = new IBaseRequest();
        String access_token = ACache.get(DaggerApplication.getIns()).getAsString("access_token");
        baseRequest.setAccess_token(access_token);
        String androidId = AndroidUtils.getAndroidId(DaggerApplication.getIns());
        baseRequest.setDevice_id(AndroidUtils.getAndroidId(DaggerApplication.getIns()));
        String refresh_token = ACache.get(DaggerApplication.getIns()).getAsString("refresh_token");
        String key = "access_token=" + access_token + "&device_id=" + androidId + "&key=" + refresh_token;
        String stringMd5 = MD5Utils.getStringMd5(key).toUpperCase();
        baseRequest.setSign(stringMd5);
        String json = new Gson().toJson(baseRequest);
        L.e("enterjson", json);
        mNetworkDateSource.getAreaInfo(baseRequest, new SubscribeResult<AreaInfoResponse>() {
            @Override
            protected void onOk(AreaInfoResponse response) {
                ((IAPPMainContact.IAPPMainView) mView).queryAreaInfoSuccess(response);
            }
            @Override
            protected void onFailure(AreaInfoResponse response){
                super.onFailure(response);
                ((IAPPMainContact.IAPPMainView) mView).queryAreaInfoFail();
            }
            @Override
            protected void onNext(AreaInfoResponse response){
                super.onNext(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {
                ((IAPPMainContact.IAPPMainView) mView).queryAreaInfoFail();
            }
        });

    }

    @Override
    public void firstSearchUserLevel() {
        IBaseRequest baseRequest = new IBaseRequest();
        String access_token = ACache.get(DaggerApplication.getIns()).getAsString("access_token");
        baseRequest.setAccess_token(access_token);
        String androidId = AndroidUtils.getAndroidId(DaggerApplication.getIns());
        baseRequest.setDevice_id(AndroidUtils.getAndroidId(DaggerApplication.getIns()));
        String refresh_token = ACache.get(DaggerApplication.getIns()).getAsString("refresh_token");
        String key = "access_token=" + access_token + "&device_id=" + androidId + "&key=" + refresh_token;
        String stringMd5 = MD5Utils.getStringMd5(key).toUpperCase();
        baseRequest.setSign(stringMd5);
        mNetworkDateSource.firstSearchUserLevel(baseRequest, new SubscribeResult<FirstSearchUserLevelRes>() {
            @Override
            protected void onOk(FirstSearchUserLevelRes response) {
                String json = new Gson().toJson(response);
                L.e(Constant.TAG, "认证等级---" + json);
                if (response.getData() == null || response.getData().getRecognitionLevel() == null) {
                    ((IAPPMainContact.IAPPMainView) mView).firstSearchUserLevelFail();
                    return;
                }
                AppHomeCardBean appHomeCardBean = new AppHomeCardBean();
                if (!StringUtils.isBlank(response.getData().getRecognitionLevel().getL3())) {
                    appHomeCardBean.setLevel("L3");
                    appHomeCardBean.setLevelDesc(response.getData().getRecognitionLevel().getL3());
                } else if (!StringUtils.isBlank(response.getData().getRecognitionLevel().getL2())) {
                    appHomeCardBean.setLevel("L2");
                    String[] split = response.getData().getRecognitionLevel().getL2().split("\\+");
                    String idCard = split[1];
                    appHomeCardBean.setIdCard(idCard);
//                    appHomeCardBean.setIdCard("");
                    appHomeCardBean.setLevelDesc(response.getData().getRecognitionLevel().getL2());
                } else if (!StringUtils.isBlank(response.getData().getRecognitionLevel().getL1())) {
                    appHomeCardBean.setLevel("L1");
                    appHomeCardBean.setLevelDesc(response.getData().getRecognitionLevel().getL1());
                }
                appHomeCardBean.setCustName(response.getData().getCustName());
                Constant.ID_NAME = response.getData().getCustName();
                Constant.USER_NAME = response.getData().getCustName();
                appHomeCardBean.setEcityCardNo(response.getData().getEcityCardNo());

                if (!StringUtils.isBlank(response.getData().getRecognitionLevel().getL2())) {
                    String[] split = response.getData().getRecognitionLevel().getL2().split("\\+");
                    appHomeCardBean.setIdCard(split[1]);
                    Constant.ID_CARD = split[1];
                    Constant.USER_IDCARD = split[1];
                }
                ((IAPPMainContact.IAPPMainView) mView).firstSearchUserLevelSucc(appHomeCardBean);
            }

            @Override
            protected void onFailure(FirstSearchUserLevelRes response) {
                super.onFailure(response);
                ((IAPPMainContact.IAPPMainView) mView).firstSearchUserLevelFail();
            }

            @Override
            protected void onNext(FirstSearchUserLevelRes response) {
                super.onNext(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {
                ((IAPPMainContact.IAPPMainView) mView).firstSearchUserLevelFail();
            }
        });
    }

    @Override
    public void queryTheme(int area_id) {
        QueryPageResourceReq pageResourceReq = new QueryPageResourceReq();
//        pageResourceReq.setResource_area_id(area_id);
        pageResourceReq.setResource_area_id(area_id);
        pageResourceReq.setAccess_token("string");
        pageResourceReq.setDevice_id("string");
        pageResourceReq.setSign("string");
        String json = new Gson().toJson(pageResourceReq);
        L.e(Constant.PATH, "pageResourceReq----->" + json);
        mNetworkDateSource.queryPageResource(pageResourceReq, new SubscribeResult<QueryPageResourceRes>() {
            @Override
            protected void onOk(QueryPageResourceRes response) {
                ((IAPPMainContact.IAPPMainView) mView).queryThemeSucc(response);
            }


            @Override
            protected void onFailure(QueryPageResourceRes response) {
                super.onFailure(response);
                Toast.makeText(DaggerApplication.getIns(), response.getMessage(), Toast.LENGTH_SHORT).show();

            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }

    @Override
    public void queryGoverList(int area_id) {
        QueryPageResourceReq pageResourceReq = new QueryPageResourceReq();
//        pageResourceReq.setResource_area_id(area_id);
        pageResourceReq.setResource_area_id(area_id);
        pageResourceReq.setAccess_token("string");
        pageResourceReq.setDevice_id("string");
        pageResourceReq.setSign("string");
        String json = new Gson().toJson(pageResourceReq);
        L.e(Constant.PATH, "pageResourceReq----->" + json);
        mNetworkDateSource.queryPageResource(pageResourceReq, new SubscribeResult<QueryPageResourceRes>() {
            @Override
            protected void onOk(QueryPageResourceRes response) {
                String json1 = new Gson().toJson(response);
                ((IAPPMainContact.IAPPMainView) mView).queryGoverListSucc(response);
            }


            @Override
            protected void onFailure(QueryPageResourceRes response) {
                super.onFailure(response);
                Toast.makeText(DaggerApplication.getIns(), response.getMessage(), Toast.LENGTH_SHORT).show();

            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }

    @Override
    public void queryMainPageFunction() {
        AccessTokenRequest accessTokenRequest = new AccessTokenRequest();
        accessTokenRequest.setAccess_token("string");
        String json = new Gson().toJson(accessTokenRequest);
        mNetworkDateSource.queryMainPageFunction(accessTokenRequest, new SubscribeResult<QueryMainPageFunctionRes>() {
            @Override
            protected void onOk(QueryMainPageFunctionRes response) {
                String json = new Gson().toJson(response);
                ((IAPPMainContact.IAPPMainView) mView).queryMainPageFunctionSucc(response.getMain_page_class_list());
            }

            @Override
            protected void onFailure(QueryMainPageFunctionRes response) {
                super.onFailure(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }

    @Override
    public void getBanner() {
        QueryPageResourceReq pageResourceReq = new QueryPageResourceReq();
//        pageResourceReq.setResource_area_id(area_id);
        pageResourceReq.setResource_area_id(45);
        pageResourceReq.setAccess_token("string");
        pageResourceReq.setDevice_id("string");
        pageResourceReq.setSign("string");
        String json = new Gson().toJson(pageResourceReq);
        L.e(Constant.PATH, "pageResourceReq----->" + json);
        mNetworkDateSource.queryPageResource(pageResourceReq, new SubscribeResult<QueryPageResourceRes>() {
            @Override
            protected void onOk(QueryPageResourceRes response) {
                String json1 = new Gson().toJson(response);
                ((IAPPMainContact.IAPPMainView) mView).getBannerSucc(response);
            }


            @Override
            protected void onFailure(QueryPageResourceRes response) {
                super.onFailure(response);
                Toast.makeText(DaggerApplication.getIns(), response.getMessage(), Toast.LENGTH_SHORT).show();

            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }

    @Override
    public void getAd(int id) {
        QueryPageResourceReq pageResourceReq = new QueryPageResourceReq();
//        pageResourceReq.setResource_area_id(area_id);
        pageResourceReq.setResource_area_id(id);
        pageResourceReq.setAccess_token("string");
        pageResourceReq.setDevice_id("string");
        pageResourceReq.setSign("string");
        String json = new Gson().toJson(pageResourceReq);
        L.e(Constant.PATH, "pageResourceReq----->" + json);
        mNetworkDateSource.queryPageResource(pageResourceReq, new SubscribeResult<QueryPageResourceRes>() {
            @Override
            protected void onOk(QueryPageResourceRes response) {
                String json1 = new Gson().toJson(response);
                ((IAPPMainContact.IAPPMainView) mView).getAdSucc(response);
            }


            @Override
            protected void onFailure(QueryPageResourceRes response) {
                super.onFailure(response);
                Toast.makeText(DaggerApplication.getIns(), response.getMessage(), Toast.LENGTH_SHORT).show();

            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }

    @Override
    public void queryText() {
        GetResourceReq getResourceRes = new GetResourceReq();
        getResourceRes.setResource_area_id(42);
        String json = new Gson().toJson(getResourceRes);
        L.e(Constant.TAG, "--------------" + json);
        mNetworkDateSource.queryInterductionArea(getResourceRes, new SubscribeResult<QueryInterductionAreaRes>() {
            @Override
            protected void onOk(QueryInterductionAreaRes response) {
                List<QueryInterductionAreaRes.InterdutionListBean> interdution_list = response.getInterdution_list();
//                L.e(Constant.TAG, "--------------" + new Gson().toJson(response));
//                for (int i = 0; i < interdution_list.size(); i++) {
//                    titleList.add(interdution_list.get(i).getContent());
//                }

                ((IAPPMainContact.IAPPMainView) mView).queryTextSucc(response);
            }

            @Override
            protected void onFailure(QueryInterductionAreaRes response) {
                super.onFailure(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }

    @Override
    public void getWeathGeneral() {
        HomeWeathReq homeWeathReq = new HomeWeathReq();
        homeWeathReq.setCityName("苏州");
        homeWeathReq.setUserId(ACache.get(DaggerApplication.getIns()).getAsString("userId"));
        mNetworkDateSource.getWeathGeneral(homeWeathReq, new SubscribeResult<HomeWeathRes>() {
            @Override
            protected void onOk(HomeWeathRes response) {
                String json = new Gson().toJson(response);
                L.e(Constant.TAG, "getWeathGeneral:" + json);
                ((IAPPMainContact.IAPPMainView) mView).getWeathGeneralSucc(response);
            }

            @Override
            protected void onFailure(HomeWeathRes response) {
                super.onFailure(response);
                ((IAPPMainContact.IAPPMainView) mView).getWeathGeneralFail(response);

            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }

    @Override
    public void selectUserAuth(final String type) {
        AccessTokenRequest accessTokenRequest = new AccessTokenRequest();
        mNetworkDateSource.selectUserAuth(accessTokenRequest, new SubscribeResult<SeleciUserAuthRes>() {
            @Override
            protected void onOk(SeleciUserAuthRes response) {
                String json = new Gson().toJson(response);
                List<SeleciUserAuthRes.AuthTypeListBean> authTypeList = response.getAuthTypeList();

                /*1.社保 2.公积金 3 桂花分*/
                SeleciUserAuthRes.AuthTypeListBean sbAuth = authTypeList.get(0);
                SeleciUserAuthRes.AuthTypeListBean gjjAuth = authTypeList.get(1);
                SeleciUserAuthRes.AuthTypeListBean ghfAuth = authTypeList.get(2);

                //0 未授权  1.已授权  2.未实名
                Constant.GHF_AUTH = ghfAuth.getIsAuth();
                Constant.SB_AUTH = sbAuth.getIsAuth();
                Constant.GJJ_AUTH = gjjAuth.getIsAuth();
                ((IAPPMainContact.IAPPMainView) mView).selectUserAuthSucc(response, type);
            }


            @Override
            protected void onFailure(SeleciUserAuthRes response) {
                super.onFailure(response);
//                Toast.makeText(DaggerApplication.getIns(), response.getMessage(), Toast.LENGTH_SHORT).show();
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }

    @Override
    public void getGetOrderId(final String url, final String type) {
        String access_token = ACache.get(DaggerApplication.getIns()).getAsString("access_token");

        GetOrderOpenid getOrderOpenid = new GetOrderOpenid();
        getOrderOpenid.setTag("HUIMIN");
        getOrderOpenid.setAccess_token(access_token);
        String json = new Gson().toJson(getOrderOpenid);
        L.e(Constant.TAG, "APPHomePresentergetOrderOpenid----->" + json);
        mNetworkDateSource.getOrderOpenid(getOrderOpenid, new SubscribeResult<GetOrderOpenidRes>() {
            @Override
            protected void onOk(GetOrderOpenidRes response) {
                String toJson = new Gson().toJson(response);
                Constant.EXTENT = response.getExtend();
                L.e(Constant.TAG, "APPHomePresentergetOrderOpenid----->" + response.getExtend());
                ACache.get(DaggerApplication.getIns()).put("mextend", response.getExtend());
                ((IAPPMainContact.IAPPMainView) mView).getGetOrderIdSucc(response, url, type);
            }

            @Override
            protected void onNext(GetOrderOpenidRes response) {
                super.onNext(response);
                String toJson = new Gson().toJson(response);
                L.e(Constant.TAG, "-------------" + toJson);
            }

            @Override
            protected void onFailure(GetOrderOpenidRes response) {
                super.onFailure(response);
                String toJson = new Gson().toJson(response);
                if (response.getCode().equals("0000")) {

                    ACache.get(DaggerApplication.getIns()).remove("mextend");
                    ACache.get(DaggerApplication.getIns()).put("mextend", response.getExtend());
                }
                L.e(Constant.TAG, "-------------" + toJson);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {
            }
        });
    }

    @Override
    public void checkSuccessOrderStatus(String access_token) {


        String access_token1 = ACache.get(DaggerApplication.getIns()).getAsString("access_token");
        if (access_token1 == null) {
            access_token1 = "2";
        }
        OkHttpUtils.post()
                .url(Constant.BASE_URL + "app/supply/CheckSuccessOrderStatusReq")
                .addParams("access_token", access_token1)
                .build()
                .execute(new StringCallback() {
                    @Override
                    public void onError(Request request, Exception e) {

                    }

                    @Override
                    public void onResponse(String response) {
                        L.e(Constant.TAG, response);
                        CloudFlashRes cloudFlashRes = new Gson().fromJson(response, CloudFlashRes.class);
                        if (cloudFlashRes != null) {
                            if (mView != null) {
                                String code = cloudFlashRes.getCode();
                                if (code.equals("000000")) {
                                    String orderStatus = cloudFlashRes.getOrderStatus();
                                    if (orderStatus != null) {
                                        ACache.get(DaggerApplication.getIns()).put("orderStatus", orderStatus);
                                    }
                                    ACache.get(DaggerApplication.getIns()).put("orderStatus", orderStatus);
                                    ((IAPPMainContact.IAPPMainView) mView).checkSuccessOrderStatusSucc(orderStatus);
//                                    ((IHomeContact.IHomeView) mView).checkSuccessOrderStatusSucc(orderStatus);
                                } else {
                                    ((IAPPMainContact.IAPPMainView) mView).checkSuccessOrderStatusFail(cloudFlashRes);
//                                    ((IHomeContact.IHomeView) mView).checkSuccessOrderStatusFail(cloudFlashRes);
                                }
                            }

                        }
                    }
                });
    }

    public void getUserInfo() {
        IBaseRequest userInfoReq = new IBaseRequest();
        String access_token = ACache.get(DaggerApplication.getIns()).getAsString("access_token");
        userInfoReq.setAccess_token(access_token);
        String androidId = AndroidUtils.getAndroidId(DaggerApplication.getIns());
        userInfoReq.setDevice_id(AndroidUtils.getAndroidId(DaggerApplication.getIns()));
        String refresh_token = ACache.get(DaggerApplication.getIns()).getAsString("refresh_token");
        String key = "access_token=" + access_token + "&device_id=" + androidId + "&key=" + refresh_token;
        String stringMd5 = MD5Utils.getStringMd5(key).toUpperCase();
        userInfoReq.setSign(stringMd5);
        String json = new Gson().toJson(userInfoReq);
        L.e(Constant.TAG, "getUserInfoZhsz:" + json);
        mNetworkDateSource.getUserInfoZhsz(userInfoReq, new SubscribeResult<IUserInfo>() {
            @Override
            protected void onOk(IUserInfo response) {
                String mobile = response.getUserEx().getMobile();
                ACache.get(DaggerApplication.getIns()).remove("mobile");
                ACache.get(DaggerApplication.getIns()).put("mobile", mobile);
                ACache.get(DaggerApplication.getIns()).put("userId", response.getUserEx().getId() + "");
                String json = new Gson().toJson(response);
                ACache.get(DaggerApplication.getIns()).put("userinfo", json);
                ((IAPPMainContact.IAPPMainView) mView).getUserInfoSucc();

            }

            @Override
            protected void onUnlogin(IUserInfo response) {
                super.onUnlogin(response);
                ((IAPPMainContact.IAPPMainView) mView).getUnlogin(response);
            }

            @Override
            protected void onNext(IUserInfo response) {
                super.onNext(response);
                ((IAPPMainContact.IAPPMainView) mView).getUserInfoFail(response);
            }


            @Override
            protected void onFailure(IUserInfo response) {
                super.onFailure(response);
//                ((IAPPMainContact.IAPPMainView) mView).getUserInfoFail(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }

    @Override
    public void queryOneWordAd() {
        IBaseRequest iBaseRequest = new IBaseRequest();
        iBaseRequest.setDevice_id("string");
        iBaseRequest.setSign("string");
        mNetworkDateSource.queryOneWordAd(iBaseRequest, new SubscribeResult<OneWordRes>() {

            @Override
            protected void onOk(OneWordRes response) {
                ((IAPPMainContact.IAPPMainView) mView).queryOneWordAdSucc(response);
            }

            @Override
            protected void onFailure(OneWordRes response) {
                super.onFailure(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }

    @Override
    public void getIsChecked(String origin, String version) {
        CheckRequest request = new CheckRequest();
        request.setOrigin(origin);
        request.setVersion(version);
        mNetworkDateSource.getIsChecked(request, new SubscribeResult<CheckRes>() {

            @Override
            protected void onOk(CheckRes response) {
                ((IAPPMainContact.IAPPMainView) mView).getIsCheckedSucc(response.getFlag());
            }

            @Override
            protected void onFailure(CheckRes response) {
                ((IAPPMainContact.IAPPMainView) mView).getIsCheckedFail();
                super.onFailure(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {
                Log.d("ss","");
            }
        });


    }

    @Override
    public void userBehaviorBrowse(int id) {
        UserBehaviorBrowseReq userBehaviorBrowseReq = new UserBehaviorBrowseReq();
        userBehaviorBrowseReq.setModularId(id);
        userBehaviorBrowseReq.setAccessToken(ACache.get(DaggerApplication.getIns()).getAsString("access_token"));

        mNetworkDateSource.userBehaviorBrowse(userBehaviorBrowseReq, new Action1<BaseBean>() {
            @Override
            public void call(BaseBean baseBean) {
                L.e(Constant.TAG, "ok----->" );
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {
            }
        });
    }

    @Override
    public void getMainNotice() {
        NoticeMainReq noticeMainReq = new NoticeMainReq();
        String access_token = ACache.get(DaggerApplication.getIns()).getAsString("access_token");
        noticeMainReq.setAccess_token(access_token);
        noticeMainReq.setDevice_id("123");
        noticeMainReq.setSign("asdf");
        String toJson = new Gson().toJson(noticeMainReq);
        L.e(Constant.TAG, "noticeMainReq----->" + toJson);
        mNetworkDateSource.getMainNotice(noticeMainReq, new SubscribeResult<NoticeMainres>() {
            @Override
            protected void onOk(NoticeMainres response) {
                if (response.getMainPageInfoList() != null) {
                    ((IAPPMainContact.IAPPMainView) mView).getMainNoticeSucc(response);
                }
            }

            @Override
            protected void onFailure(NoticeMainres response) {
                super.onFailure(response);

                ((IAPPMainContact.IAPPMainView) mView).getMainNoticeError(response.getMessage());
            }

            @Override
            protected void onNext(NoticeMainres response) {
                super.onNext(response);
                ((IAPPMainContact.IAPPMainView) mView).getMainNoticeError(response.getMessage());
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

                ((IAPPMainContact.IAPPMainView) mView).getMainNoticeError(throwable.getMessage());
            }
        });
    }

    public void userBehaviorActivity(){
        UserBehaviorReq baseRequest = new UserBehaviorReq();
        if(ACache.get(DaggerApplication.getIns()).getAsString("access_token")!=null){
            baseRequest.setAccessToken(ACache.get(DaggerApplication.getIns()).getAsString("access_token"));
        }else{
            baseRequest.setAccessToken("");
        }
        baseRequest.setDeviceId(AndroidUtils.getAndroidId(DaggerApplication.getIns()));
        mNetworkDateSource.userBehaviorActive(baseRequest, new SubscribeResult<BaseBean>() {
            @Override
            protected void onOk(BaseBean response) {
                Log.i("tag","ok");
            }

            @Override
            protected void onFailure(BaseBean response) {
                super.onFailure(response);
            }
        }, new ErrorAction() {
            @Override
            public void onCall(Throwable throwable) {

            }
        });
    }

    public class CheckRequest{
        private String origin;
        private String version;

        public String getOrigin() {
            return origin;
        }

        public void setOrigin(String origin) {
            this.origin = origin;
        }

        public String getVersion() {
            return version;
        }

        public void setVersion(String version) {
            this.version = version;
        }
    }

    public class CheckRes extends BaseBean {

        private String flag;



        public String getFlag() {
            return flag;
        }

        public void setFlag(String flag) {
            this.flag = flag;
        }

    }


}
